from typing import Any, Optional, Generic, TypeVar
from pydantic.generics import GenericModel

T = TypeVar("T")

class Response(GenericModel, Generic[T]):
    code: int = 200
    message: str = "success"
    data: Optional[T] = None

    @classmethod
    def success(cls, data: Any = None, message: str = "success") -> "Response":
        return cls(
            code=200,
            message=message,
            data=data
        )

    @classmethod
    def error(cls, code: int = 400, message: str = "error") -> "Response":
        return cls(
            code=code,
            message=message
        )
